<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Config Qbv</title>
    <script src="static/jquery.min.js">
    </script>
    <style>
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 4px 6px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 13px;
    margin: 2px 1px;
    -webkit-transition-duration: 0.4s; /* Safari */
    transition-duration: 0.4s;
    cursor: pointer;
}
.device {
    background-color: white; 
    color: black; 
    border: 2px solid #4CAF50;
    -webkit-transition-duration: 0.1s; /* Safari */
    transition-duration: 0.1s;
    border-radius: 5%;
}
.device:hover {
    background-color: #4CAF50;
    color: white;
}
.confirm {
    background-color: #4CAF50; 
    color: black; 
    position: center;
    font-weight: bold;
    font-size: 15px;
    border: 2px solid #4CAF50;
    border-radius: 5%;
}
.confirm:hover {
    background-color: #4CAF50;
    color: white;
}
.addlist {
    background-color: white; 
    color: black; 
    padding: 2px 6px;
    font-weight: bold;
    border: 2px solid #4CAF50;
    border-radius: 100%;
}
.addlist:hover {
    background-color: #4CAF50;
    color: white;
}
</style>
</head>
<body>
<script>
var portname = window.parent.deviceport;
var enable = 'false';
var preemptset = {};
var devname = window.parent.devicename;

function tabledisplay()
{
	var tc_num = 8;

	if (devname.indexOf("imx") >= 0)
		tc_num = 5;

	for (var i = 0; i < tc_num; i++)
		document.getElementById("tc"+i).style.display="block";
}

function selectpreempt()
{
	var i = 0;
	$('input:radio[value="preemptable"]').each(function(){
				if ($(this).is(":checked")) {
					enable = 'true';
					return false; //measn break;
				}
				i++;
			});
	if (i == 8) {
		enable = 'false';
	}
}

function selectenable()
{
	var radioVal = $('input:radio[name="enable"]:checked').val();
	if (radioVal == "false") {
		$('input:radio[value="express"]').each(function() {
					$(this).attr("checked", "checked");
				});
	} else {
		selectpreempt();
		radioVal = "false";
	}

	enable = radioVal;
	console.log(enable);
}

function confirmset()
{
	var i = 0;
	var deviceself = window.parent.formgetnameip();

	preemptset['device'] = deviceself['deviceip'];
	preemptset['plist'] = [];
	preemptset['port'] = portname;//$("#portselect").val();

	$('input:radio[value="preemptable"]').each(function(){
				if ($(this).is(":checked"))
					preemptset['plist'].push({tc: i, preemptable: "preemptible"});
				else
					preemptset['plist'].push({tc: i, preemptable: "express"});
				i++;
			});
	preemptset['enable'] = enable;
	console.log(preemptset);

	$.ajax({
		type: "POST",
		url: "/qbuset",
		dataType: "json",
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify(preemptset),
		success: function(data){
			if (data.status == 'false')
				alert('Feedback ERROR!');
				
			$('#outputcontent', parent.document).append("<pre>"+"editconfig operation: "+data.status+"</pre>");
			window.parent.showconfig("if:interfaces", data.getconfig);
			window.parent.showconfig("dot1q:bridges", data.getconfig);
			window.parent.showconfig("bridges", data.getconfig);
			window.parent.showconfig("interfaces", data.getconfig);
			$('#outputcontent', parent.document).append("<pre>"+'-------------------------'+window.parent.counter+'-------------------------'+"</pre>");
			window.parent.counter += 1;
		}});
}
</script>

<div>
<form>
<b>*device:
<br>&nbsp;&nbsp;
<table>
	<tr id="tc0" style="display: block;">
		<td><b>TC0</b><input class="button addlist" type="radio" name="tc0" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc0" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc1" style="display: none;">
		<td><b>TC1</b><input class="button addlist" type="radio" name="tc1" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc1" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc2" style="display: none;">
		<td><b>TC2</b><input class="button addlist" type="radio" name="tc2" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc2" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc3" style="display: none;">
		<td><b>TC3</b><input class="button addlist" type="radio" name="tc3" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc3" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc4"style="display: none;">
		<td><b>TC4</b><input class="button addlist" type="radio" name="tc4" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc4" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc5" style="display: none;">
		<td><b>TC5</b><input class="button addlist" type="radio" name="tc5" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc5" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc6" style="display: none;">
		<td><b>TC6</b><input class="button addlist" type="radio" name="tc6" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc6" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr>
	<tr id="tc7" style="display: none;">
		<td><b>TC7</b><input class="button addlist" type="radio" name="tc7" value="preemptable" onclick="selectpreempt()">preemptable</td>
		<td><input class="button addlist" type="radio" name="tc7" value="express" onclick="selectpreempt()"  checked="checked">express</td></tr></table>
<br><br><br><b>
<input class="button device confirm" type="button" name="confirm" id="confirm" onclick="confirmset()" value="Yes, confirm">
<script>
	tabledisplay();
</script>
</form>
</div>
</body>
</html>
